package com.mydomain.debtbook;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import android.util.Log;

public class BiDiMap<String, Double> {
	private Map<String, Double> keyToValueMap = new ConcurrentHashMap<String, Double>();
	private Map<Double, String> valueToKeyMap = new ConcurrentHashMap<Double, String>();

	public void put(String key, Double value) {

		keyToValueMap.put(key, value);
		valueToKeyMap.put(value, key);

	}

	public void syncKeyValue() {
		valueToKeyMap.clear();
		Set<Map.Entry<String, Double>> set = keyToValueMap.entrySet();

		for (Map.Entry<String, Double> me : set) {
			valueToKeyMap.put(me.getValue(), me.getKey());
		}

	}

	public Double removeByKey(String key) {

		return keyToValueMap.remove(key);
		
	}

	public String removeByValue(Double value) {


			String removedKey = valueToKeyMap.remove(value);
			keyToValueMap.remove(removedKey);
			return removedKey;

	}

	public boolean containsKey(String key) {
		return keyToValueMap.containsKey(key);
	}

	public boolean containsValue(Double value) {
		return keyToValueMap.containsValue(value);
	}

	public String getKey(Double value) {

		return valueToKeyMap.get(value);

	}

	
	
	public Collection values() {
		return keyToValueMap.values();
	}
	
	
	public Collection keys() {
		return keyToValueMap.keySet();
	}

	public int size() {
		return keyToValueMap.size();
	}

	public Double get(String key) {

		return keyToValueMap.get(key);
	}

	public String keyToString() {
		return (String) keyToValueMap.toString();
	}

	public String valueToString() {
		return (String) valueToKeyMap.toString();
	}

}